<template>
    <rx-dialog @handOk="handleSubmit" @cancel="cancel">
        <rx-layout>
            <div slot="center">
                <a-alert
                    message="系统支持Jenkins「流水号、文件夹、多分支流水线」类型的任务。关联Jenkins后，你可以在「流水线管理」管理和追踪该类流水线。"
                    type="info"
                    show-icon
                />
                <a-form-model layout="vertical" ref="form"  :model="mdl" :rules="rules" >
                    <a-form-model-item  label="JenkinsURL" prop = "url">
                        <a-input placeholder="请输入JenkinsURL" v-model="mdl.url"/>
                    </a-form-model-item>
                    <a-form-model-item  label="备注名" prop = "name">
                        <a-input placeholder="请输入备注名" v-model="mdl.name"/>
                    </a-form-model-item>
                    <a-form-model-item  label="Jenkins用户名" prop = "userName">
                        <a-input placeholder="请输入Jenkins用户名" v-model="mdl.userName"/>
                    </a-form-model-item>
                    <a-form-model-item  label="API Token" prop = "pwd">
                        <a-input-password placeholder="请输入API Token" v-model="mdl.pwd"/>
                    </a-form-model-item>
                    <a-form-model-item  label="启用" prop = "state">
                        <a-switch v-model="state" @change="stateChange" />
                    </a-form-model-item>
                </a-form-model>
            </div>
        </rx-layout>
    </rx-dialog>
</template>
<script>
import SysJenkinsApi from "@/api/system/core/sysJenkins";
import {RxDialog, BaseFormModel} from '@lowcode/jpaas-common-lib';

export default {
    name: 'SysJenkinsEdit',
    mixins: [BaseFormModel],
    components: {
        RxDialog,
    },
    data() {
        return {
            /**
             * 子表列表，以及表格属性
             */
            subTable: {},
            rules: {
                name: [{ required:true,message: "请输入备注名", trigger: 'change' }],
                url: [{ required:true,message: "请输入JenkinsURL", trigger: 'change' }],
                userName: [{ required:true,message: "请输入Jenkins用户名", trigger: 'change' }],
                pwd: [{ required:true,message: "请输入API Token", trigger: 'change' }],
            },
            state:false
        }
    },
    methods: {
        onload_(values){
            if(values){
                this.state = values.state===1;
            }
        },
        get(id) {
            return SysJenkinsApi.get(id);
        },
        save() {
            this.mdl.state = this.state?1:0;
            return SysJenkinsApi.save(this.mdl);
        },
        stateChange(e){
            this.mdl.state =e ? 1 : 0;
        }
    }
}
</script>
<style scoped>

</style>
